// pages/my/my.js
const app = getApp()
const TOKEN = 'token'
const {apiName}  = require('../../api/http/my')
var timr
Page({
  /**
   * 页面的初始数据
   */
  data: {
    margin:'20',
    src: '',
    active: 0,
    listH:575
  },
  async laftTap (e){
  // const token = wx.getStorageSync(TOKEN)
  // if(token && token.length!==0){
  //   app.globalData.token = token
  //   return 
  // }
  const res = await apiName({account:'admin',password:'haixing888@2222'})
  console.log(res.data.data.accessToken);
  return
   _request({
      url: 'http://api.haixingmama.com/admin/login',
      method:'post',
      data:{account:'admin',password:'haixing888@2222'}
    }).catch(err=>{
      console.log(err,'err');
    }).then(res=>{
      console.log(app.globalData.token);
      console.log(res);
    })
  },
  activeTap(e){
    this.setData({
      active:+e.target.id.slice(e.target.id.length-1,e.target.id.length)
    })
  },
  toCropper() {
    wx.navigateTo({
        url: `/cropper/cropper?imgSrc=${this.data.src}`
    })
},
goPersonal(){
  wx.navigateTo({
    url: '/pages/my/personal-details/index',
  })
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const {navigationHei,navigationTop} = wx.getStorageSync('navigation')
    app.globalData.marginTop = navigationHei + navigationTop
    this.setData({
      margin:navigationHei + navigationTop
    })
    let that = this
    if (app.globalData.token) {
        that.getData()
    } else {
      app.getloginCallback = (v) => {
        console.log(v);
        if (v) {
          that.getData()
        }
      }
    }
  
  },
  getData(){
    console.log('getData');
    let windowHeight = wx.getSystemInfoSync().windowHeight // 屏幕的高度
    let windowWidth = wx.getSystemInfoSync().windowWidth // 屏幕的宽度
    wx.createSelectorQuery().select('#intro').boundingClientRect((rect) => {
      wx.createSelectorQuery().select('#data').boundingClientRect((rect1) => {
        let listH =  windowHeight - rect.height - rect1.height
        this.setData({listH})
      }).exec();
    }).exec();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (app.globalData.imgSrc) {
      this.setData({
          src: app.globalData.imgSrc
      })
  }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    clearTimeout(timr)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return{
      title:'分享我的页面',
      path:'/pages/my/my',
      imageUrl:'https://img2.baidu.com/it/u=3193353500,3694580136&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=664'
    }
  }
})